function setScreenToSession() 
{ 
	var width = screen.width;
	var height = screen.height;
	var param = "type=setClientScreen&screenWidth=" + width + "&screenHeight=" + height;
	loadPage("core/toolctrl", param, null, null, null, null, null);
}

/**
 *显示信息提示
 */
function showMsgTable(msg)
{
	// 隐藏登陆进度条
	hideProgressBar();
	var table = document.getElementById('error_table');
	table.rows[0].cells[1].innerHTML = " " + decodeURIComponent( msg );
	table.style.visibility = "visible";
}
function cleanMsgTable()
{
	var table = document.getElementById('error_table');
	table.style.visibility = "hidden";
}
/**
 * 显示登陆进度条
 */
function showProgressBar()
{
	var progressBar = $('progressdiv');
	if(progressBar != null)
		progressBar.style.display = "block";
}

/**
 * 隐藏登陆进度条
 */
function hideProgressBar()
{
	var progressBar = $('progressdiv');
	if(progressBar != null)
		progressBar.style.display = "none";
}

function changeLocale(select)
{
	document.cookie = "GUEST_LANGUAGE_ID=" + select.options[select.selectedIndex].value;
	window.location.href = "nclogin.jsp";
}

function showOption()
{
	if(document.getElementById('option_table').style.visibility == "hidden")
		document.getElementById('option_table').style.visibility = "visible";
	else
		document.getElementById('option_table').style.visibility = "hidden";
}

function forceLogin()
{ 
	var form = getComponent("nclogin_form");
	var div = document.getElementById("$d_nclogin_formuserId");
	var loginInput = document.createElement("input");
	loginInput.type = "hidden";
	loginInput.value = "force";
	loginInput.name = "loginFlag";
	div.appendChild(loginInput);
	
	loadForm(document['nclogin_form'], 'securitycheck', submitCallback, null);
}

function cancelLogin()
{
	var errinfo = null;
	if(cancelLogin.errinfo != null)
		errinfo = cancelLogin.errinfo
	showMsgTable(errinfo);
	delete(cancelLogin.errinfo);
}

function toClose(){
	window.opener = null;
	window.open("", "_self");
	window.close();
}
/*普通登录*/
function valid()
{
	var form = getComponent("nclogin_form");
	var div;
	var loginUITypeValue= getSessionAttribute('loginUIType');
	if(loginUITypeValue == '0'){//普通登录
		div = document.getElementById("$d_nclogin_formaccountCode");
		if(window.accInput == null){
			accInput = document.createElement("input");
			accInput.type = "hidden";
			accInput.name = "accountCodeValue";
			accInput.value = form.getElement("accountCode").getValue();
			div.appendChild(accInput);
			
			dsInput = document.createElement("input");
			dsInput.type = "hidden";
			dsInput.name = "datasource";
			dsInput.value = window.$nc_corp_datasource;
			div.appendChild(dsInput);
			
			corpCodeInput = document.createElement("input");
			corpCodeInput.type = "hidden";
			corpCodeInput.name = "corpCode";
			var ds = getDataset("nclogin_ds");
			var corpCode = ds.getValueAt(0, ds.nameToIndex('corpCode'));
			if(corpCode == null)
				corpCode = "";
			corpCodeInput.value = corpCode;
			div.appendChild(corpCodeInput);
		}
	}else{
		div = document.getElementById("$d_nclogin_formuserId");
	}
	var loginInput = document.createElement("input");
	loginInput.type = "hidden";
	loginInput.name = "loginUIType";
	loginInput.value = loginUITypeValue;
	div.appendChild(loginInput);

	var maxWindowInput = document.createElement("input");
	maxWindowInput.type = "hidden";
	maxWindowInput.name = "maxWindow";
	var maxWindowEle = document.getElementById("maxWindowBox");
	if(maxWindowEle.checked)
		maxWindowInput.value = "1";
	else
		maxWindowInput.value = "0";
	div.appendChild(maxWindowInput);
	
	var compressWindowInput = document.createElement("input");
	compressWindowInput.type = "hidden";
	compressWindowInput.name = "compressStream";
	var compressEle = document.getElementById("compressStream");
	if(compressEle.checked)
		compressWindowInput.value = "1";
	else
		compressWindowInput.value = "0";
	div.appendChild(compressWindowInput);
	// 显示登陆进度条
	showProgressBar();
	loadForm(document['nclogin_form'], 'securitycheck', submitCallback, null);
}
/*简单登录
 * v[0] = accountCode;v[1] =corpCode
 * */
function valid4SimpleLogin(v) 
{
	var form = getComponent("nclogin_form");
	var div = document.getElementById("$d_nclogin_formuserId");
	var ds = getDataset("nclogin_ds");
	var row = ds.getRow(0);

	if(window.accInput == null){
		accInput = document.createElement("input");
		accInput.type = "hidden";
		accInput.name = "accountCodeValue";
		accInput.value = v[0];//form.getElement("accountCode").getValue();
		div.appendChild(accInput);
		
		dsInput = document.createElement("input");
		dsInput.type = "hidden";
		dsInput.name = "datasource";
		dsInput.value = window.$nc_corp_datasource;
		div.appendChild(dsInput);
		
		corpCodeInput = document.createElement("input");
		corpCodeInput.type = "hidden";
		corpCodeInput.name = "corpCode";
		var corpCode = v[1];
		if(corpCode == null)
			corpCode = "";
		corpCodeInput.value = corpCode;
		div.appendChild(corpCodeInput);
	}

	var loginInput = document.createElement("input");
	loginInput.type = "hidden";
	loginInput.name = "loginUIType";
	loginInput.value = "1";
	div.appendChild(loginInput);
	
	var loginInput2 = document.createElement("input");
	loginInput2.type = "hidden";
	loginInput2.name = "loginUIType2";
	loginInput2.value = "1";
	div.appendChild(loginInput2);
	
	var maxWindowInput = document.createElement("input");
	maxWindowInput.type = "hidden";
	maxWindowInput.name = "maxWindow";
	var maxWindowEle = document.getElementById("maxWindowBox");
	if(maxWindowEle.checked)
		maxWindowInput.value = "1";
	else
		maxWindowInput.value = "0";
	div.appendChild(maxWindowInput);
	
	var compressWindowInput = document.createElement("input");
	compressWindowInput.type = "hidden";
	compressWindowInput.name = "compressStream";
	var compressEle = document.getElementById("compressStream");
	if(compressEle.checked)
		compressWindowInput.value = "1";
	else
		compressWindowInput.value = "0";
	div.appendChild(compressWindowInput);
	
	showProgressBar();
	loadForm(document['nclogin_form'], 'securitycheck', submitCallback, null);
}

function afterPageInit() 
{
	var ds = getDataset('nclogin_ds');
	ds.setRowSelected(0);
	window.$nc_corp_datasource = getSessionAttribute('defaultDatasource');
	window.$lastDatasourceName = window.$nc_corp_datasource;
	var form = getComponent('nclogin_form');
	var loginUIType= getSessionAttribute('loginUIType');
	if(loginUIType == '1')
		return;
	var refComponent = form.getElement('corpName');
	
	/**
	 * 参照框打开时设置当前帐套对应数据源
	 */
	refComponent.beforeOpenRefDialog = function()
	{	
		if(window.$nc_corp_accountcode == null)
			return 'sys_datasource=' + window.$nc_corp_datasource;
		
		if(window.$lastDatasourceName != window.$nc_corp_datasource){     
			this.setRefresh(true);
			window.$lastDatasourceName = window.$nc_corp_datasource;
		}
		// 记录参照上次的ds
		window.$lastDatasourceName = window.$nc_corp_datasource;
		return 'sys_datasource=' + window.$nc_corp_datasource;
	}
	
	/**
	 * 监测帐套数据的改变
	 */
	getDataset("nclogin_ds").onAfterDataChange = function(event)
	{
		if(event.cellColIndex == this.nameToIndex('accountCode'))
		{
			//帐套改变则清空其它
			if(event.currentValue != event.oldValue){
				ds.setValueAt(0,ds.nameToIndex("corpCode"),null);
				ds.setValueAt(0,ds.nameToIndex("corpName"),null);
				ds.setValueAt(0,ds.nameToIndex("userId"),null);
			}
			
			var row = this.getSelectedRow();
			var account = row.getCellValue(this.nameToIndex('accountCode'));
			if(account != null) {
				window.$nc_corp_accountcode = account;
			}
			
			// 建立帐套和数据源的对应关系
			if(window.$accountDsMap == null)
				window.$accountDsMap = new HashMap();
			var currentDatasource = window.$accountDsMap.get(window.$nc_corp_accountcode);	
			if(currentDatasource == null) 
			{ 
				var cmd = new CommonCommand('findDatasourceByAccountCode');
				cmd.setParameter('accountCode=' + window.$nc_corp_accountcode);
				cmd.setAsync(false);
				var resultDs = cmd.exec();
				currentDatasource = resultDs[0];
				window.$accountDsMap.put(window.$nc_corp_accountcode, currentDatasource);
			}
			// 设置当前数据源
			window.$nc_corp_datasource = currentDatasource;
			//alert("设置当前数据源:" + window.$nc_corp_datasource);
		}	
	}
} 

function beforeProcessReferenceEnter(ref) {
	return "datasource=" + window.$nc_corp_datasource;
}